package com.bishe.tax.utils.job;

import com.bishe.tax.entity.RegistrationInfo;
import com.bishe.tax.entity.TaxRegistration;
import com.bishe.tax.service.RegistrationInfoService;
import com.bishe.tax.service.TaxRegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2020/4/9.
 */
@Component
public class StartUpJob {

    @Autowired
    private RegistrationInfoService registrationInfoService;
    @Autowired
    private TaxRegistrationService taxRegistrationService;

    @Scheduled(cron = "*/10 * * * * ?")
    public void testJob() {
        RegistrationInfo info = new RegistrationInfo();
        info.setStatus(4);
        List<RegistrationInfo> inList = registrationInfoService.selectInfoList(info);
        inList.forEach(registrationInfo -> {
            if (registrationInfo.getRiContinueTime()!=null && registrationInfo.getRiContinueTime().getTime() < new Date().getTime()){
                registrationInfo.setStatus(0);
                registrationInfoService.updateInfo(registrationInfo);
                TaxRegistration taxRegistration = taxRegistrationService.selectRegistrationById(registrationInfo.getTaxReId());
                taxRegistration.setInfoId(-1);
                taxRegistrationService.updateRegistration(taxRegistration);
            }
        });
    }
}
